<template>
	<view class='part-list-box'>
		<view class='list' v-if="partEntities">
			<view class='item' v-for="(part, index) in partEntities" :key="index">
				<view class='top'>
					<view class='line'>
						<div class='left'><text
								class="number">{{part.partName || '--'}}</text><span>|</span>{{part.typeName || '--'}}
						</div>
						<div class='right'>
							<text style="color: #fff;padding: 2px 8px;border-radius: 2px;"
							:class="part.status==0?'part-status-0':(part.status==1?'part-status-1':(part.status==2?'part-status-2':(part.status==3?'part-status-3':(part.status==4?'part-status-4':(part.status==5?'part-status-5':(part.status==6?'part-status-6':'part-status-7'))))))"
							>{{part.status==0?'采购中':(part.status==1?'已入库':(part.status==2?'已出库':(part.status==3?'制造中':(part.status==4?'检验中':(part.status==5?'制造完成':(part.status==6?'组装中':'已完成'))))))}}</text>
						</div>
					</view>
					<view class='line'>
						<text
							class="model">{{part.projectName || '--'}}</text>
					</view>
					<view class='line'>
						<text
							class="model">{{part.specifications || '--'}}</text><span>|</span>{{part.material || '--'}}
					</view>
					<view class='line'>
						<text class="model">{{part.model || '--'}}</text><span>|</span>{{part.number || '--'}}
					</view>
				</view>
				<view class='createTime'>
					<view>
						<text class="iconfont icon-rili"></text>入库时间：
						<uni-dateformat :date="part.inTime" format='yyyy-MM-dd hh:mm:ss'></uni-dateformat>
					</view>
					<view>
						<uni-tooltip placement="top">
							<view>更多</view>
							<template slot="content">
								<a @click="updateSingle(part)">编辑</a>
							</template>
						</uni-tooltip>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more iconType="circle" v-if="partEntities.length" :status="loadingStatus"></uni-load-more>
		<o-empty v-else bg="#f3f3f3"></o-empty>
	</view>
</template>

<script>
	import {
		api,
		post
	} from '@/util/api.js'
	export default {
		props: {
			projectId: '',
			deviceId: ''
		},
		data() {
			return {
				partEntities: [],
				count: 0,
				page: 1,
				limit: 10,
				loadingStatus: 'more',
			}
		},
		created() {
			this.queryList()
		},
		methods: {
			async queryList() {
				let part = {
					deviceId: this.deviceId,
					page: this.page,
					limit: this.limit
				}
				let res = await post(api.PartEntities, part)
				this.count = res.count
				this.loadingStatus = "more"
				this.partEntities = [...this.partEntities, ...res.data]
			},
			deleteSingle(part) {
				
			},
			updateSingle(part) {
				uni.navigateTo({
					url: '/pages/project/part/AddPart?projectId=' + this.projectId + '&deviceId=' + this.deviceId + '&partId=' + part.id
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/css/PartList.css';
</style>
